package edu.ccdb.irods;

import java.sql.Connection;
import java.sql.DriverManager;

public class CCDB_V2_1Service {
	// Load the driver when this class is first loaded
    static {
    	try {
            Class.forName( PostgresConfiguration.DB_DRIVER ).newInstance();
        } catch (ClassNotFoundException cnfx) {
            cnfx.printStackTrace();
        } catch (IllegalAccessException iaex) {
            iaex.printStackTrace();
        } catch (InstantiationException iex) {
            iex.printStackTrace();
        }
    }
    
    /**
     * Returns a normal connection to the database
     * @return Connection
     */
    public static Connection getConnection () {
         try {
            return  DriverManager.getConnection( PostgresConfiguration.URL_CCDBV2_1,
        				PostgresConfiguration.USERNAME, PostgresConfiguration.PASSWORD);
        } catch (Exception e) {
            e.printStackTrace();
            return  null;
        }
    }
    
    /**
     * Static method that releases a connection
     * @param con the connection
     */
    public static void closeConnection (Connection con) {
        try {
            if (con != null) {
                con.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
